package com.thientan.service

import com.thientan.export.ExportRequest
import com.thientan.model.ThongKePhieuThu
import com.thientan.utils.Utility

class ThongKePhieuThuService extends AbstractService {
	/**
	 * Return the widths of columns in the export file when export list of domains.
	 */
	protected Long[] getColWidth() {
		return [80,	120, 140, 140, 140, 120, 180] as Long[]
	}

	/**
	 * Return the column's headers in the export file when export list of domains.
	 * */
	protected String[] getColTitles() {
		return [
			"Ngày lập",
			"Số phiếu nhận",
			"Số phiếu trả hết",
			"Số phiếu trả hàng",
			"Số phiếu đền hàng",
			"Số phiếu giao",
			"Tổng số phiếu còn lại ở công ty"] as String[]
	}

	/**
	 * Return the fields of domain to export.
	 * */
	protected String[] getColNames() {
		return [
			"ngayLapText",
			"soPhieuNhan",
			"soPhieuTraHet",
			"soPhieuTraHang",
			"soPhieuDenHang",
			"soPhieuGiao",
			"soPhieuCty"] as String[]
	}

	/**
	 * Return the type of columns when export list of domains.
	 * */
	@SuppressWarnings("rawtypes")
	protected Class<?>[] getExportColType() {
		return [
			String.class,
			BigDecimal.class,
			BigDecimal.class,
			BigDecimal.class,
			BigDecimal.class,
			BigDecimal.class,
			BigDecimal.class] as Class<?>[]
	}
	
	void prepareParametersBeforeExport(ExportRequest er){
		er.addParameter("ngayXuat", this.exportData?.ngayXuat)
		er.addParameter("thoiGian", this.exportData?.thoiGian)
	}
	
	ThongKePhieuThu fetchOrCreateThongKePt() {
		ThongKePhieuThu object = ThongKePhieuThu.findByNgayLap(Utility.dateWithoutTime())
		return object ?: new ThongKePhieuThu()
	}
}
